//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.TridentModelSL
{
    using System.Collections.ObjectModel;
    using service = Microsoft.Research.ScientificWorkflow.TridentSilverlightService;

    /// <summary>
    /// The category model.
    /// </summary>
    public sealed class CategoryModel : BaseModel
    {
        /// <summary>
        /// The child models.
        /// </summary>
        private ObservableCollection<BaseModel> children = new ObservableCollection<BaseModel>();

        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <value>The children.</value>
        public ObservableCollection<BaseModel> Children
        {
            get
            {
                return this.children;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CategoryModel"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        public CategoryModel(service.LeftPaneModel source)
        {
            this.Name = source.name;
            this.Label = source.label;
            this.Id = source.id;

            this.ItemIcon = BaseModel.CreateImage(@"../../Images/CategoriesHeader.png");

            foreach (service.LeftPaneModel child in source.children)
            {
                //if (!child.IsDeleted && (!string.IsNullOrEmpty(child.VersionLabel) || Activity.IsLatestVersion(child)))
                {
                    if (child.isCategoryModel)
                    {
                        this.Children.Add(new CategoryModel(child));
                    }
                    else
                    {
                        this.Children.Add(new WorkflowModel(child));
                    }
                }
            }
        }
    }
}
